const fs = require('fs');
const path = require('path');
const { utilJavaApiParser } = require('./dist/u_api_parser');
const { utilTemplate } = require('./dist/u_template');
function run() {
    const txt = fs.readFileSync('./feiwuxingren.json', 'utf8');
    const json = JSON.parse(txt);
    const schemas = utilJavaApiParser.parseSchemas(json, (key) => {
        if (key === '响应结果') return true;
        if (key == 'R') return true;
        if (key == 'PageVo') return true;
        if (key.indexOf('«') > -1) return true;
        if (key == 'Page') return true;
        return false;
    });
    const now = new Date();
    const time = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()} ${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`
    let timeHeader = `// 生成时间 ${time} \n`;
    console.log(timeHeader);

    fs.writeFileSync(path.join(__dirname, 'tmp/class.d.ts'), timeHeader + utilTemplate.genInterface(schemas), 'utf8');
    const httpList = utilJavaApiParser.parsePaths(json, '/dev-api');
    timeHeader = `//MARK: 接口数量: ${httpList.length}\n//--\n//--\n//--\n//--\n` + timeHeader;
    fs.writeFileSync(path.join(__dirname, 'tmp/http.d.ts'), timeHeader + utilTemplate.genInterface(httpList), 'utf8');

}
function getTtypeList() {
    let str = 'R«Page«Blacklist»»';
    const reg = /\«([^\«]+?)\»/;
    let list = [];
    while (reg.test(str)) {
        const ret = str.match(reg);
        if (ret) {
            list.push(ret[1]);
            str = str.replace(ret[0], '');
        }
        if (!reg.test(str)) {
            list.push(str);
        }
    }
    // .match(/\<([^\<]+?)\>/)
    return list;
}
(function () {
    run();
    // console.log(
    //     getTtypeList()
    // );

})();